Ext.namespace("Dudley");
Ext.namespace("Dudley.lims");

Dudley.lims.PhyloTree = function() {

    var phyloPanel = {};
    var showAll = 1,
        showGeo = 0,
        showSource = 0;
    var vis = null;

    function loadPhyloPanel() {
        phyloPanel = new Ext.Panel({
            id: "phyloPanelId",
            autoHeight: true,
            border: true,
            renderTo: "pg-form",
            title: "Phylogenetic Tree",
            header: false
        });
        phyloPanel.on("activate", function () {
            Ext.getDom("pg-form").innerHTML = "";
            Ext.getDom("pg-canvas").innerHTML = "";
            loadJSPhylo(null, "circular");
        });
    }

    function getPhyloSearchOptionsArray() {
    return [
        ['all', 'All'],
        ['Plant_Material_Soil', 'Plant_Material_Soil'],
        ['Alcoholic_Fermentation', 'Alcoholic_Fermemtation'],
        ['Food_Baker_Chocolate', 'Food_Baker_Chocolate'],
        ['Clinical', 'Clinical'],
        ['more', 'more']
    ];
}

    function loadPhyloCombo(){
        var phyloOptionsStore = new Ext.data.SimpleStore({
            fields: ['key', 'value'],
            data : getPhyloSearchOptionsArray()
        });
        var phyloCombo = new Ext.form.ComboBox({
            store: phyloOptionsStore,
            id: 'phyloComboId',
            fieldLabel: 'Sources and Features',
            displayField:'value',
            valueField:'key',
            typeAhead: true,
            mode: 'local',
            emptyText:'All',
            triggerAction: 'all',
            forceSelection:true,
            selectOnFocus:true
        });
         phyloCombo.on("select", function (c, r, i) {
            if (i != 0) {
                showAll = 0;
                if (i == 1){
                    showSource = 1;
                }
                if (i == 2){
                    showGeo = 1;
                }
            }else{
                showAll = 1;

            }
             vis.render();
        });
        return new Ext.form.FormPanel({
            id: 'phyloupdateForm',
            method: 'POST',
            autoHeight: true,
            renderTo: "pg-form",
            width: 800,
            title: '',
            items: [
                {
                    layout:'column',
                    items:[
                        {
                            columnWidth:.75,
                            border: false,
                            layout: 'form',
                            items: [ phyloCombo]
                        }
                    ]
                }
            ]
        });
    }

    function buildPhyloTree() {
        var species = ["plant_material_soil", "alcoholic_fermentation", "food_baker_chocolate", "clinical"];
        var color = pv.colors(
                "#ffe",//"rgba(50%, 0%, 0%, .5)",
                "#ff7f0e",//rgba(0%, 50%, 0%, .5)",
                "#aec7e8",
                "rgba(25%, 0%, 0%, .5)");

        vis = new pv.Panel()
                .width(1000)
                .height(875)
                .left(50)
                .right(-75)
                .top(-20)
                .bottom(525)
                .canvas("pg-phylo");

        var tree = vis.add(pv.Layout.Tree)
                .nodes(pv.dom(mockNVStrains).root("").nodes())
                .depth(55)
                .breadth(15)
                .bottom(525)
                .left(50)
                .right(400)
                .top(10)
                .group(1)
                .orient("radial");

        tree.link.add(pv.Line)
                .strokeStyle(function(n) {
                return styleEdge(n);
        });

        tree.node.add(pv.Dot)
                .event("click", function(nv){
                    alert("NV Strain " + nv.nodeName + " coded with " + nv.nodeValue);
                })
                .fillStyle(function(n) {
                    return styleNode(n);
                    }).size(function(d) {
                        if (d.nodeValue == -1) {
                            return 12;
                        }else if (d.nodeValue == -2){
                            return 12;
                        }else if (d.nodeValue == -3){
                            return 12;
                        }
                           return d.nodeValue / 500;
                });

        tree.label.add(pv.Label);

        tree.add(pv.Label)
                .left(-25)
                .top(26)
                .textAlign("left")
                .text("* sequenced");


        tree.add(pv.Dot)
                .data(species)
                .top(20)
                .left(function() {return 75 + this.index * 150;})
                .size(20)
                .strokeStyle("00bfff")
                .fillStyle(color)
                .event("click", function(n){
                    alert("clicked on " + n);
                })
                .anchor("right").add(pv.Label)
                .visible(function(d) { return showAll == 1;});
      
        tree.add(pv.Rule)
                .data([1,50,100,150,200,250])
                .top(function(){ return this.index * 40 + 40;})
                .left(-25)
                .width(50)
                .lineWidth(2)
                //.interpolate("step-after")
                .strokeStyle(function(d) {
                        if (d == 1){
                            return "red";
                        }else if (d == 50){
                            return "blue";
                        }else if (d == 100){
                            return "green";
                        }else if (d == 150){
                            return "#aec7e8";
                        }else if (d == 200){
                            return "yellow";
                        }else if (d == 250){
                            return "#ff7f0e";
                        }
                })
                .anchor("right").add(pv.Label)
                .textMargin(10)
                .textAlign("right")
                .left(100)
                .text(function(d) {
                        if (this.index == 0){
                            return "africa";
                        }else if (this.index == 1){
                            return "asia";
                        }else if (this.index == 2){
                            return "europe";
                        }else if (this.index == 3){
                            return "north america";
                        }else if (this.index == 4){
                            return "south america";
                        }else if (this.index == 5){
                            return "oceania";
                        }
                });
        vis.render();
    }


    function styleLegend(val){
        if (val == "asia"){
            return "green";
        }
        if (val == "africa"){
            return "blue";
        }
    	return "red";

    };

    function styleNode(node){
        if (node.firstChild){
            return "#aec7e8";
        }else{
    	    if (node.nodeValue == -1){
    		    return "#ffe";
    	    }else if (node.nodeValue == -2){
                return "#aec7e8";
            }else if (node.nodeValue == -3){
                return "#ff7f0e";
            }
    	return "black";
        }
    };

    function styleEdge(node){
        var confidence = node.nodeName;
        if (confidence != undefined && confidence.indexOf("_") != -1 ){
            if (confidence.indexOf("YO") == -1){
                confidence = confidence.substring(0, confidence.indexOf("_"));
            }
        }
        node.nodeName = confidence;
        var confidenceInt = parseInt(confidence);
        if (confidenceInt != undefined && confidenceInt > 75){
            return "green";
        }
        if (node.firstChild){
            return "#aec7e8";
        }
    	return "blue";
    };

function showd(obj,id,lft,top) {
 var el = document.getElementById(id);
 el.style.display = "block";
 el.style.left=zxcPos(obj)[0]+lft+'px';
 el.style.top=zxcPos(obj)[1]+top+'px';
}

function zxcPos(obj){
 var rtn=[obj.offsetLeft,obj.offsetTop];
 while(obj.offsetParent!=null){
  var objp=obj.offsetParent;
  rtn[0]+=objp.offsetLeft-objp.scrollLeft;
  rtn[1]+=objp.offsetTop-objp.scrollTop;
  obj=objp;
 }
 return rtn;
}

function createDiv(id, cssClass, remark)
    {
        var divTag = document.createElement(id);
        divTag.id = id;
        divTag.className =cssClass;
        divTag.innerHTML = remark + "&nbsp;<FONT color='cyan'>Africa</FONT>&nbsp;<FONT color='green'>Asia</FONT>&nbsp;<FONT color='purple'>Australia/Oceania</FONT>&nbsp;<FONT color='orange'>Europe</FONT>&nbsp;<FONT color='red'>North America</FONT>&nbsp;<FONT color='blue'>South America</FONT>&nbsp;<FONT color='black'>Unknown</FONT>&nbsp;";
        document.getElementById("pg-phylo").appendChild( divTag );
    }

function loadJSPhylo(newickText, layout) {

        Ext.fly('pg-phylo').update('');
        //var dataStr = '((((((((((((((((((((((((YO295:0.00038603,YO325:0.00030199):0.00000884,YO293:0.00040970):0.00000396,(YO23:0.00030367,YO4:0.00032299):0.00002504):0.00000043,(YO15:0.00031140,YO644:0.00035489):0.00003818):0.00001040,((YO26:0.00012487,YO291:0.00012253):0.00023424,(YO3:0.00034296,YO322:0.00039296):0.00003903):0.00002232):0.00002311,(YO407:0.00083030,(YO652:0.00034725,((YO650:0.00042132,YO708:0.00030451):0.00002455,(YO656:0.00034208,(YO654:0.00016795,(YO658:0.00002471,YO659:0.00004016):0.00029815):0.00002096):0.00004834):0.00006835):0.00057904):0.00010562):0.00001852,(YO458:0.00031488,(YO299:0.00064062,(YO324:0.00027575,(YO676:0.00023784,YO690:0.00023004):0.00017874):0.00010467):0.00002950):0.00000924):0.00006762,(YO680:0.00043729,((YO687:0.00035937,YO688:0.00029091):0.00005723,(YO696:0.00001222,YO697:0.00002831):0.00045010):0.00013453):0.00013250):0.00003912,(YO689:0.00102053,((YO692:0.00003465,YO693:-0.00000422):0.00068263,(((YO681:0.00001456,YO695:-0.00000544):0.00000529,(YO691:0.00002086,YO694:0.00002632):0.00000889):0.00034776,((((YO677:0.00000411,YO686:0.00001729):0.00000316,YO684:0.00002043):0.00000756,YO685:0.00000405):0.00013617,(YO682:0.00000861,(YO683:0.00002137,(YO678:0.00000932,YO679:0.00002483):0.00001232):0.00001033):0.00016038):0.00032606):0.00029538):0.00007369):0.00004988):0.00008892,YO301:0.00122006):0.00007185,(YO642:0.00104639,(YO715:0.00087054,YO737:0.00152686):0.00051234):0.00066407):0.00009507,(((YO315:0.00015800,YO323:-0.00000311):0.00007286,YO313:0.00002034):0.00065551,(YO304:0.00075216,(YO321:0.00017660,(YO25:0.00001325,(YO12:0.00005666,(YO18:0.00004130,YO307:0.00004081):0.00001091):0.00002976):0.00000530):0.00014150):0.00037140):0.00016147):0.00001859,(YO376:0.00137722,(((YO365:0.00002848,YO366:0.00002957):0.00022633,YO369:-0.00000457):0.00008162,((YO364:0.00009009,YO375:0.00008972):0.00007585,(YO368:0.00017192,YO370:0.00018217):0.00007215):0.00004010):0.00089742):0.00012537):0.00001919,YO297:0.00150798):0.00005610,(YO720:0.00076801,(YO702:0.00128964,(YO710:0.00158082,(((YO289:0.00078521,YO726:0.00065616):0.00003467,YO19:0.00071965):0.00020603,(YO292:0.00047540,(YO410:0.00087226,(((((YO362:0.00004234,YO363:0.00007586):0.00029615,YO367:0.00025006):0.00022592,YO465:0.00054863):0.00002311,YO673:0.00041153):0.00003830,(YO725:0.00062110,(YO722:0.00040260,(YO703:0.00020387,(YO707:0.00030669,YO723:0.00030487):0.00014836):0.00007569):0.00005375):0.00004789):0.00010628):0.00004026):0.00011451):0.00008452):0.00010460):0.00013746):0.00010490):0.00010762,YO701:0.00100625):0.00004115,(YO730:0.00309276,(YO466:0.00177411,YO663:0.00139427):0.00011649):0.00009496):0.00007928,((((YO384:-0.00001915,YO388:0.00004628):0.00094184,YO537:0.00028622):0.00054043,YO731:0.00160768):0.00024703,((YO418:0.00008075,YO419:0.00000902):0.00099058,(YO414:0.00072788,(YO417:0.00037249,(YO416:0.00020935,(YO415:0.00014368,YO420:0.00009693):0.00005213):0.00013772):0.00038629):0.00041739):0.00072339):0.00003503):0.00008802,(YO728:0.00133248,(YO662:0.00118496,YO7:0.00162868):0.00009834):0.00002331):0.00004430,(YO306:0.00144948,YO320:0.00140270):0.00032084):0.00001148,(YO294:0.00137015,YO319:0.00166701):0.00013211):0.00007961,(YO671:0.00023848,YO733:0.00024442):0.00104872):0.00002055,YO719:0.00112153):0.00008379,(YO316:0.00094543,(YO669:0.00013965,YO705:0.00011280):0.00095278):0.00031985,((((((((YO729:0.00021524,YO734:0.00016216):0.00009785,YO736:0.00024259):0.00091856,YO721:0.00151785):0.00005389,YO700:0.00175118):0.00022260,YO468:0.00176895):0.00001811,(YO668:0.00080296,YO670:0.00067168):0.00041473):0.00015696,(YO371:0.00005323,(YO373:0.00002743,(YO372:0.00006741,YO374:0.00006925):0.00003741):0.00004343):0.00143940):0.00002779,(((YO314:0.00160563,YO716:0.00117465):0.00013673,YO645:0.00131928):0.00006499,((((YO22:0.00075112,YO303:0.00081737):0.00046579,YO24:0.00043342):0.00069003,YO17:0.00079597):0.00116889,(YO727:0.00183283,(YO11:0.00192813,((YO305:0.00020534,YO317:0.00034680):0.00160727,(((YO14:0.00000267,YO298:0.00001513):0.00001091,YO6:0.00000243):0.00266877,((((((((YO312:0.00000980,YO665:0.00004308):0.00001443,YO357:0.00000195):0.00000424,YO311:0.00000897):0.00000886,YO359:0.00000983):0.00076070,YO358:0.00086308):0.00036317,(YO433:0.00001993,(YO327:0.00001557,(YO20:0.00000865,YO331:0.00000026):0.00000630):0.00003992):0.00115731):0.00015778,(YO399:0.00131431,(YO290:0.00070471,(YO318:0.00000412,YO356:0.00001890):0.00072741):0.00035373):0.00022614):0.00030775,((YO704:0.00141724,YO709:0.00146514):0.00032163,((((YO646:0.00000106,YO647:0.00015361):0.00124518,YO732:0.00124426):0.00015140,YO672:0.00108219):0.00010649,(YO641:0.00079143,(YO706:0.00106244,(YO667:0.00069169,(((((YO408:0.00002195,YO411:0.00005846):0.00019485,YO643:0.00014021):0.00012859,(YO409:0.00031694,YO717:0.00026086):0.00005900):0.00022497,YO649:0.00070081):0.00015255,(YO666:0.00061133,(((YO651:0.00008048,YO718:0.00002648):0.00041060,YO648:0.00043461):0.00017829,((YO10:0.00021527,YO308:0.00016038):0.00005235,(YO16:0.00020646,YO309:0.00021477):0.00001947):0.00032438):0.00012718):0.00004018):0.00006677):0.00012897):0.00009174):0.00035243):0.00029234):0.00014096):0.00009481):0.00017526):0.00015737):0.00011279):0.00018399):0.00025832):0.00006246):0.00008076);';
        var dataStr = '((((((((((((((YO23_DBVPG6765_Unk_Unk:0.00028779,YO4_DBVPG 1788_Finland_Europe_Finland__soil:0.00033886)0.8300:0.00004957,YO293_DBVPG1106_Australia_Oceania_Island__wine:0.00038764)0.1800:-0.00001716,(YO295_L1528_Chile_South America___Wine:0.00039732,YO325_M22a _Italy_Europe_Italy__wine:0.00029071)0.2950:0.00002062)0.1500:0.00000666,(YO15_L1374_Chile_South America___wine:0.00033694,YO644_NRRL Y1532_Indonesia_Asia_Indonesia__fruit:0.00032935)0.7350:0.00003385)0.4650:0.00001530,((YO26_YJM978_Italy_Europe__Clinical Isolate_Vaginal:0.00012006,YO291_YJM981_Italy_Europe__Clinical Isolate_Vaginal:0.00012734)1.0000:0.00022077,(YO3_DBVPG 1373_Netherlands_Europe_Netherlands__soil:0.00032346,YO322_CLIB215_New Zealand_Oceania_New Zealand collected in 1994__Bakers yeast:0.00041245)0.9750:0.00005251)0.8650:0.00001573)0.9450:0.00008021,(YO458_TOT_United States_North America_Masia de Yabar Winery Temecula County CA__Soil and olive leaf at base of olive tree:0.00038165,(YO299_BC187 UCD2120_United States_North America___wine:0.00057458,(YO324_WE372_South Africa_Africa_Cape Town South Africa__wine:0.00028759,(YO676_Soil1_New Zealand_Oceania___Soil:0.00025760,YO690_Soil 15_New Zealand_Oceania___soil:0.00021029)1.0000:0.00016690)0.9700:0.00013138)0.7500:-0.00002682)0.7400:0.00000099)0.4850:0.00006642,(YO407_UCD 7512 UCD Enology num 519_Unk_Unk_unknown__Flor sherry yeast from Dr Kunkee Dept of Enology UCD their num 519 Wine strain Flor Universal Food Corp:0.00079776,(YO708_Y12657_Spain_Europe___olives:0.00039462,(YO652_Kalamata 1_United States_North America_from a store__Olive Bar at PCC Fremont:0.00029853,YO654_Kalamata K3_United States_North America_from a store__Olive Bar at PCC Fremont:0.00025104)0.9250:0.00007601)1.0000:0.00060603)0.9300:-0.00000140)0.5300:0.00023194,(((((YO696_Bark 1_New Zealand_Oceania___bark unknown tree:0.00000912,YO697_Bark 2_New Zealand_Oceania___bark unknown tree:0.00003141)1.0000:0.00029148,YO688_Soil 132_New Zealand_Oceania___soil:0.00034728)0.8450:0.00010930,YO687_Soil 131_New Zealand_Oceania___soil:0.00048150)1.0000:0.00007258,YO680_Soil 4_New Zealand_Oceania:0.00048057)1.0000:0.00023834,(YO689_Soil 14_New Zealand_Oceania___soil:0.00093520,((YO692_Soil 171_New Zealand_Oceania___soil:0.00003397,YO693_Soil 172_New Zealand_Oceania___soil:-0.00000354)1.0000:0.00068469,(((YO681_Soil 5_New Zealand_Oceania___soil:0.00001480,YO695_Buttercup 1_New Zealand_Oceania:-0.00000568)0.9300:0.00000605,(YO691_Soil 16_New Zealand_Oceania___soil:0.00001734,YO694_Buttercup 2_New Zealand_Oceania___flower buttercup:0.00002984)0.7700:0.00000813)1.0000:0.00039134,((((YO677_Soil 2_New Zealand_Oceania___soil:-0.00000092,YO686_Soil 112_New Zealand_Oceania___soil:0.00002232)0.4750:0.00000122,YO684_Soil 9_New Zealand_Oceania___soil:0.00002237)0.4900:0.00000788,YO685_Soil 111_New Zealand_Oceania___soil:0.00000370)1.0000:0.00013654,(YO682_Soil 71_New Zealand_Oceania___soil:0.00000316,(YO683_Soil 72_New Zealand_Oceania___soil:0.00002170,(YO678_Soil 31_New Zealand_Oceania___soil:0.00000633,YO679_Soil 32_New Zealand_Oceania___soil:0.00002781)0.9550:0.00001199)0.8500:0.00001397)1.0000:0.00015062)1.0000:0.00028175)1.0000:0.00031855)0.9950:0.00012774)1.0000:-0.00013229)0.5300:-0.00007972)1.0000:0.00036488,YO301_I14_Italy_Europe_Soil sample in Petrina Italy in 2002__soil vineyard:0.00094424)0.9950:0.00000413,YO642_NRRL Y1547_Italy_Europe_Italy_Food_Stracchino cheese:0.00147307)0.8200:0.00004038,YO720_Y502_Unk_Unk__Clinical Isolate_CHRONIC LUNG DISEASE:0.00083206)1.0000:0.00018660,(((YO365_EC14_Israel_Asia_North Face__leaf  station 6:0.00002795,YO366_EC14p_Israel_Asia_North Face__leaf north facing European side station 6:0.00003010)1.0000:0.00021665,YO369_EC34_Israel_Asia_South Face shady__shady station 3:0.00000511)1.0000:0.00007684,((YO364_EC13_Israel_Asia_North Face__Leaf station 6:0.00010762,YO375_EC60_Israel_Asia_South Face sunny station 6__sunny spot:0.00007219)0.9900:0.00009061,(YO368_EC33_Israel_Asia_south facing African side station 3__shady spot station 3:0.00018142,YO370_EC35_Israel_Asia_South Face __sunny spot south face:0.00017267)0.9800:0.00005740)0.9950:0.00003355)1.0000:0.00072320)0.9150:0.00009334,(YO304_CBS7960_Brazil_South America_Factory producing ethanol from cane sugar syrup  Sao Paulo Brazil__Factory producing EtOH from sugar cane:0.00079890,(YO321_YJM280_United States_North America_US pre1994_Clinical Isolate_peritoneal fluid:0.00016967,(YO25_K11_Japan_Asia___Sake:0.00000717,(YO12_322134S_United Kingdom_Europe__Clinical Isolate_sputum:0.00006095,(YO18_YIIC17E5_France_Europe___wine:0.00004056,YO307_CLIB324_Vietnam_Asia___Bakers yeast collected in 1996:0.00004155)0.7300:0.00000662)0.9650:0.00003365)0.6600:0.00000616)1.0000:0.00009996)1.0000:0.00030750)0.9150:0.00008196,(YO313_YJM653_Unk_Unk__Clinical Isolate_Clinical sample isolated from bronchoalveolar lavage:0.00000889,(YO315_T73_Spain_Europe_Alicante Spain in 1987__Red wine prepared from a Monastrel grape in fermentation stage:0.00016974,YO323_FL100_Unk_Unk_Laboratory strain collected pre1968_Unk_Unk:-0.00001485)1.0000:0.00008432)1.0000:0.00042850,(((YO22_DBVPG6044_Unk_Africa___Bili Wine:0.00074927,YO303_PW5_Nigeria_Africa___Raphia palm wine 2002:0.00081922)1.0000:0.00041324,YO24_NCYC110_Unk_Africa___Ginger Beer:0.00048598)1.0000:0.00136245,(((YO14_UWOPS034614_Malaysia_Asia___Nectar Bertram Palm Race uvarum:0.00000464,YO298_UWOPS052173_Malaysia_Asia___palm nectar:0.00001317)0.8700:0.00000983,YO6_UWOPS052272_Malaysia_Asia_Southeast Asia__Trigona stingless bee Bertram Palm:0.00000351)1.0000:0.00260680,((((((((YO312_YPS1009___Mettler Woods New Jersey in 2000__Oak tree exudates:0.00000619,YO665_Y12603_India_Asia___fermented food:0.00004669)0.8900:0.00001464,YO357_CP1_United States_North America___Oak tree soil:0.00000174)0.5400:0.00000368,YO311_NC02_United States_North America_Smoky Mountains of North Carolina in 2003__Oak tree exudates:0.00000851)0.8500:0.00000855,YO359_TN1 TN5C_United States_North America___Oak tree soil:0.00000834)1.0000:0.00075557,YO358_IN1_United States_North America___Oak tree soil:0.00087737)0.9750:0.00031116,(YO433_LASPR_United States_North America_pink rhododendron flower Letitia Ave S Seattle WA USA__rhododendron flowers:0.00002161,(YO327_YPS163 a_United States_North America_Pennsylvania oak tree__oak tree:0.00001596,(YO20_YPS128_United States_North America___oak tree:0.00001084,YO331_UWOPS87 a_Unk_Unk__Unk_unknown:-0.00000193)0.6850:0.00000591)1.0000:0.00003486)1.0000:0.00109125)0.8100:0.00013302,(YO399_UCD 61190_United States_North America_Peach orchard near Winters CA 72861 __Isolated from Drosophila pseudoobscura:0.00130253,(YO290_UWOPS837873_Bahamas_North America_Island__fruit prickly pear cactus:0.00074121,(YO318_T7_United States_North America_Babler State Park Missouri in 2003__Oak tree exudates :0.00000317,YO356_BW1 BW 12_United States_North America_Black Water MO USA__Oak tree soil:0.00001985)1.0000:0.00069092)0.9750:0.00030332)0.8050:0.00023391)1.0000:0.00027480,((((YO646_NRRL Y12617_India_Asia_India__fermented food:0.00000163,YO647_NRRL Y12717_Nepal_Asia_Nepal__Murcha yeast cake:0.00015304)1.0000:0.00126788,YO732_Y999 Erb amanite_Unk_Unk___Amylo process isolating EtOH from starch:0.00122155)0.9900:0.00010964,YO672_Y7563_India_Asia___Jalebi Indian fried sweet snack:0.00107355)0.8550:0.00006807,(YO641_NRRL Y7662_Mexico_North America_Mexico__Pozol cacaobased drink:0.00074994,(YO706_Y12844_Philippines_Asia___Bubod rice wine starter:0.00104064,(YO667_Y1791_Unk_Unk__Food_cheese:0.00073459,(((((YO408_UCD 7915_Unk_Unk_UCD colection note Received by Dr Lewis Feb 27 1979__sake:0.00002066,YO411_UCD 629_Japan_Asia_Received 862 from Dr K Arima Univ of Tokyo by Tom Nakayama __sake:0.00005974)1.0000:0.00019038,YO643_NRRL YB1779_Brazil_South America_Brazil__Rice mash:0.00014468)1.0000:0.00013834,(YO409_UCD 852_Japan_Asia_UCD collection note Marilyn UCD Vand E num 611__sake:0.00031427,YO717_Y11574 IFO 2141_Unk_Unk___SAKE YEAST:0.00026353)1.0000:0.00006774)1.0000:0.00022227,YO649_NRRL YB1013_China_Asia_China__Fermented food:0.00069738)1.0000:0.00016374,(YO666_Y12679_China_Asia___Lao chao fermented rice product:0.00061584,(((YO651_NRRL Y12658_Unk_Unk_unk__pig rectal contents:0.00007926,YO718_Y17447 PINTHONG 196_Thailand_Asia___SEWAGE  SEDIMENT DRAINAGE POND THAILAND:0.00002770)1.0000:0.00041545,YO648_NRRL Y12769_Malaysia_Asia_Malaysia__Tapioca:0.00042976)1.0000:0.00016943,((YO10_Y12_Ivory Coast_Africa_Africa__palm wine:0.00021495,YO308_Y12_Ivory Coast_Africa___Palm wine pre1981:0.00016070)0.9800:0.00005343,(YO16_Y9_Indonesia_Oceania_Island__Ragi African or finger millet:0.00021254,YO309_Y9_Indonesia_Asia___Ragi African or finger millet i pre1962:0.00020870)0.7850:0.00001839)1.0000:0.00032148)1.0000:0.00011620)0.8350:0.00008537)0.9150:0.00006170)1.0000:0.00008782)0.7750:0.00006958)1.0000:0.00032718)1.0000:0.00058934)0.8150:0.00024340)1.0000:0.00016872)1.0000:0.00147251);';
        if (newickText != null){
            dataStr  = newickText;
        }
        var dataObject = {newick: dataStr};
        Smits.PhyloCanvas.Render.Parameters.onClickAction = function(o){
            mainPanel.activate(samplesPanel);
            Dudley.lims.YOStrain.loadStrain(o.node.name.split("_")[0].replace("YO", "YO"));
        };
        var height = 800;
        var width = 750;
        if (layout == "rectangular"){
            height = 1500;
            if (newickText.length > 2000){
                height = 3000;
            }
        }
          var phylocanvas = new Smits.PhyloCanvas(
                dataObject,
                'pg-phylo',
                height,
                width,
                layout
                );
        initutip();
        if (newickText == null || newickText.indexOf("YO") != -1)
            createDiv("phylolegendTopId", "dynamicDivTop", "");
    };

    // public
    return {
        getPhyloPanel: function() {
            loadPhyloPanel();
            return phyloPanel;
        },
        loadPhyloFromPrompt: function(newick, layout){
            Ext.getDom("pg-form").innerHTML = "";
            Ext.getDom("pg-canvas").innerHTML = "";
            if (newick == null || newick.length == 0){
                newick = null;
            }
            loadJSPhylo(newick, layout);
        }
    };
}();
